
cc.Class({
    extends: cc.Component,

    properties: {

    },
    updateTurn(){
        this.node.scaleX = Math.cos(this.time  / this.duration*Math.PI) * this.scaleX
        let scaleXPercent = Math.abs(this.node.scaleX /this.scaleX)
        if(scaleXPercent>1){
            scaleXPercent =1
        }
        let minLight = 100
        this.node.color = new cc.Color(minLight+(255-minLight) *scaleXPercent,minLight+(255-minLight) *scaleXPercent,minLight+(255-minLight) *scaleXPercent)
    },

    turn(){
        this.time =0
        this.turnFinished = false
        this.scaleX = this.node.scaleX
    },
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.time =0
        this.turnFinished = true
        this.duration = 0.4

        if(this.node.scaleX>0){
            this.scaleX = 1
        }else{
            this.scaleX = -1
        }
        // this.node.scaleX
    },

    update (dt) {
        if(!this.turnFinished){
            if(this.time<this.duration){
                this.updateTurn()
                this.time+=dt
            }else{            
                this.turnFinished = true
                this.node.color = new cc.Color(255,255,255)
                if(this.node.scaleX >0){
                    this.node.scaleX = Math.abs(this.scaleX)
                }else{
                    this.node.scaleX = - Math.abs(this.scaleX)
                }
            }
        }        
    },
});
